package com.shikong.blog.service.impl;

import com.shikong.blog.common.Response;
import com.shikong.blog.enums.ResponseCodeEnum;
import com.shikong.blog.exception.BizException;
import com.shikong.blog.model.systemvo.file.UploadFileRspVO;
import com.shikong.blog.service.AdminFileService;
import com.shikong.blog.util.TencentcosUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description: TODO
 **/
@Service
@Slf4j
public class AdminFileServiceImpl implements AdminFileService {

    @Autowired
//    private MinioUtil minioUtil;
    private TencentcosUtil tencentcosUtil;

    @Override
    public Response uploadFile(MultipartFile file) {
        try {
//            String url = minioUtil.uploadFile(file);
            String url = tencentcosUtil.upload(file);
            return Response.success(UploadFileRspVO.builder().url(url).build());
        } catch (Exception e) {
            log.error("==> 上传文件异常: ", e);
            throw new BizException(ResponseCodeEnum.UPLOAD_FILE_ERROR);
        }
    }
}
